package com.sentrix.auto.printercenter.infrastructure.persistence.impl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.sentrix.auto.printercenter.domain.entity.PrinterTaskEntity;
import com.sentrix.auto.printercenter.infrastructure.persistence.IPrinterTaskRepository;
import com.sentrix.auto.printercenter.infrastructure.persistence.dao.mapper.PrinterTaskMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class IPrinterTaskRepositoryImpl extends ServiceImpl<PrinterTaskMapper, PrinterTaskEntity> implements IPrinterTaskRepository {

    @Override
    public Page<PrinterTaskEntity> pageQuery(int currentPage, int pageSize, String orderNo, String printerCode, String agentName, String printerName) {
        return this.page(Page.of(currentPage, pageSize), query()
                .eq(PrinterTaskEntity::getOrderNo, orderNo, StringUtils.isNotBlank(orderNo))
                .or(q->q.eq(PrinterTaskEntity::getPrinterCode, printerCode),StringUtils.isNotBlank(printerCode))
                .or(q->q.eq(PrinterTaskEntity::getAgentName, agentName), StringUtils.isNotBlank(agentName))
                .or(q->q.eq(PrinterTaskEntity::getPrinterName, printerName), StringUtils.isNotBlank(printerName))
        );
    }
}
